package cn.openea.perpartner.meily.web.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.meily.web.entity.Evaluation;
import cn.openea.perpartner.meily.web.entity.dto.SearchDto;
import cn.openea.perpartner.meily.web.mapper.EvaluationMapper;
import cn.openea.perpartner.meily.web.service.IEvaluationService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * (Evaluation)表服务实现类
 *
 * @author Weird077
 * @since 2023-01-29 15:55:46
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements IEvaluationService {

    @Override
    public List<Evaluation> selectList(SearchDto dto) {
        LambdaQueryWrapper<Evaluation> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(dto.getSearchStr())){
            wrapper.and(wrap-> wrap.like(Evaluation::getSubject,dto.getSearchStr())
                    .or().like(Evaluation ::getDemandNo,dto.getSearchStr()));
        }
        wrapper.orderByDesc(Evaluation::getCreateTime);
        return list(wrapper);
    }

    @Override
    public String createDemandNo(String prefix,int randomSize) {
        String format = "yyMMddhhmmssSSS";
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String dateString = formatter.format(currentTime);
        String numStr = "";
        for (int i = 0; i < randomSize; i++) {
            numStr += (int) (10 * (Math.random()));
        }
        return prefix+dateString + numStr;
    }

    @Override
    public boolean migrate(List<Evaluation> evaluationList) {

        return saveBatch(evaluationList);
    }
}

